<!doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" Content="text/html; charset=utf-8"/>

	<link rel="stylesheet" type="text/css" href="../css/header.css">
	<link rel="stylesheet" type="text/css" href="../css/footer.css">
	<link rel="stylesheet" type="text/css" href="../css/notice_board.css">
	<link rel="stylesheet" type="text/css" href="../css/notice_board_edit.css">
	<link rel="stylesheet" href="../res/bootstrap/css/bootstrap.min.css">
	<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.js"></script>
	<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/jquery-ui.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
	<script type="text/javascript" src="../js/notice_board_edit.js"></script>
	<script type="text/javascript" src="../se2/js/HuskyEZCreator.js"></script>
	<script src="../myUtil.js"></script>
<script>
  var oEditors = [];
  
  $(function() {
    nhn.husky.EZCreator.createInIFrame({
      oAppRef: oEditors,
      elPlaceHolder: "textarea1",
      sSkinURI: "../se2/SmartEditor2Skin.html",        
      fCreator: "createSEditor2"
  });
    
  
    
  });
    var myModule = angular.module('myModule', []);
	
    myModule.controller('MyController', function ($scope, $http,$location) {
        $scope.items = [];
        $scope.subjectItems=[];
        $scope.id='';
        $scope.subject=null;
        $scope.files=[];
        $scope.notice_ck=0;
        $scope.content_id=$location.search().content_id;
        $scope.submit=function(){
        	
        	oEditors.getById["textarea1"].exec("UPDATE_CONTENTS_FIELD", []);
        }
        $scope.loadSubject = function() {
        	
        	myUtil.onHttp($http,'get','subject.do',null,null,function(data) {
        		$scope.subjectItems=data;
        		
        		if($location.search().content_id!=null){
        			
            		myUtil.onHttp($http,'get','content.do',{content_id:$location.search().content_id},null,function(data) {
            			
            			if(data.subject!=null){
            			
            				for(i=0 ; i<$scope.subjectItems.length ; ++i){
            					
            					if($scope.subjectItems[i].subject_id==data.subject.subject_id){
            					
            						$scope.subject=$scope.subjectItems[i].subject_id;
      							
            					}
            				
            				}
            			}
            			
            			$scope.content=data.content.content;
            			$scope.title=data.content.title;
            		});
            	
                    myUtil.onHttp($http, 'get', 'fileList.do', {content_id:$location.search().content_id}, null, function(data){
                    	$scope.files=data;
                    })
            	};
        	});
        	
        	
        }
        $scope.loadUser = function(){
        	myUtil.onHttp($http, 'get', 'user.do', null, null, function(data){
        		$scope.id=data;
        	})
        }
        $scope.loadUser = function(){
        	myUtil.onHttp($http, 'get', 'user.do', null, null, function(data){
        		$scope.id=data;
        	})
        }
       
		$scope.fileDelete=function(index){
			if(confirm("정말 파일을 삭제 하시겠습니까?")){
				myUtil.onHttp($http, 'get', 'fileDelete.do', {file_id:$scope.files[index].file_id}, null, function(data){
	        		if(data=='false'){
	        			alert("삭제 실패!");
	        		}
	        		else{
	        			$scope.files.splice(index,1);
	        		}
	        	})
			}
		}
        $scope.loadUser();
        $scope.loadSubject();
        
       
    });
   
</script>
<script> 
    $(function(){
      $(".header").load("header.html");$(".footer").load("footer.html"); 
    });
</script> 

</head>
<body ng-app="myModule">
<div class="container" ng-controller="MyController">
<!-- header-->
<div class="header span12">
</div>

<!--notice_content-->
<h1>공지사항</h1> 새로운 공지사항을 등록
<br/>
<form action="{{content_id ? 'modify.do' : 'write.do'}}" method="post" enctype="multipart/form-data" ng-submit="submit()">
	<div class="span2">카테고리</div>
	<input name="board_id" type="hidden" value="1"/>
	<input type="hidden" name="subject" value="{{subject}}"/>
	<input type="hidden" name="notice_ck" value="{{notice_ck}}"/>
	<input type="hidden" name="content_id" value="{{content_id}}"/>
	
	<select class="span2" ng-model="subject" ng-options="option.subject_id as option.name for option in subjectItems">
		<option value="">없음</option>
	</select>
	
	<br/><div class="span2">제목 </div><input ng-model="title" name="title" id="notice_name" type="text"/>
	<br/><div class="span2">파일 첨부 </div>
	<div class="span5">
	<a ng-repeat-start="file in files" ng-click="download(file.file_id)">●{{file.file_name}}</a>
	<a ng-repeat-end><span ng-click="fileDelete($index)">&times;<br/></span></a>
	</div>
	<br/><br/><br/>
	
	<button type="button" class="btn btn-info" onclick="notice_file_add()">파일추가</button>
	<div id="file_add"></div><!--추가되는 파일 이름과 id는 notice_file-->
	<br/><div class="span2">중요 공지 여부</div> 
	<input id="notice_ck" type="checkbox" ng-true-value="1" ng-false-value="0" ng-model="notice_ck"/>  
	<div class="info"><i class="icon-info-sign"></i>주요 공지 여부 체크시 항시 붉은색 글자로 상위에 표시</div>
	
	<textarea name="content" id="textarea1" name="content" ng-model="content"  class="span11 notice_content"></textarea>
	
	
	<div class="button"><input type="submit" class="btn btn-primary" value="등록">&nbsp;&nbsp;<a class="btn" href="notice.html">취소</a></div>
</form>
<!--//notice_content-->

<!--footer-->
	
	<div class="footer span12"></div>
<!--//footer-->
</div>
</body>
</html>